package fr.uniscol.exception.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import fr.uniscol.controller.UniscolRootController;

public class UniscolHandlerExceptionResolver implements HandlerExceptionResolver {

	private String viewError;
	
	public String getViewError() {
		return viewError;
	}

	public void setViewError(String viewError) {
		this.viewError = viewError;
	}

	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
		
		ModelAndView model = new ModelAndView(UniscolRootController.JSP_CADRE);
		
		model.getModelMap().addAttribute("JSP_INCLUSE", viewError);
		model.getModelMap().addAttribute("erreur", ex);
		
		ex.printStackTrace();
		
		return model;
	}
}
